package o;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor.e;
import o.aea.a;

public final class aew implements e {
    @Nullable
    private final long[] ʼ;
    private final int ˊ;
    private final long ˋ;
    private final long ˎ;
    private final long ˏ;
    private final long ॱ;

    @Nullable
    public static aew ˋ(long j, long j2, aed o_aed, anc o_anc) {
        int i = o_aed.ᐝ;
        int i2 = o_aed.ˊ;
        int ॱᐝ = o_anc.ॱᐝ();
        if ((ॱᐝ & 1) == 1) {
            int ʽॱ = o_anc.ʽॱ();
            if (ʽॱ != 0) {
                long ॱ = anr.ॱ((long) ʽॱ, ((long) i) * 1000000, (long) i2);
                if ((ॱᐝ & 6) != 6) {
                    return new aew(j2, o_aed.ॱ, ॱ);
                }
                long ʽॱ2 = (long) o_anc.ʽॱ();
                long[] jArr = new long[100];
                for (ʽॱ = 0; ʽॱ < 100; ʽॱ++) {
                    jArr[ʽॱ] = (long) o_anc.ʽ();
                }
                if (!(j == -1 || j == j2 + ʽॱ2)) {
                    amz.ˏ("XingSeeker", "XING data size mismatch: " + j + ", " + (j2 + ʽॱ2));
                }
                return new aew(j2, o_aed.ॱ, ॱ, ʽॱ2, jArr);
            }
        }
        return null;
    }

    private aew(long j, int i, long j2) {
        this(j, i, j2, -1, null);
    }

    private aew(long j, int i, long j2, long j3, @Nullable long[] jArr) {
        long j4 = -1;
        this.ॱ = j;
        this.ˊ = i;
        this.ˎ = j2;
        this.ʼ = jArr;
        this.ˋ = j3;
        if (j3 != -1) {
            j4 = j + j3;
        }
        this.ˏ = j4;
    }

    public boolean ˊ() {
        return this.ʼ != null;
    }

    public a ˏ(long j) {
        if (!ˊ()) {
            return new a(new aeh(0, this.ॱ + ((long) this.ˊ)));
        }
        double d;
        long ˎ = anr.ˎ(j, 0, this.ˎ);
        double d2 = (((double) ˎ) * 100.0d) / ((double) this.ˎ);
        if (d2 <= 0.0d) {
            d = 0.0d;
        } else if (d2 >= 100.0d) {
            d = 256.0d;
        } else {
            int i = (int) d2;
            long[] jArr = (long[]) amm.ॱ(this.ʼ);
            double d3 = (double) jArr[i];
            d = (((i == 99 ? 256.0d : (double) jArr[i + 1]) - d3) * (d2 - ((double) i))) + d3;
        }
        return new a(new aeh(ˎ, anr.ˎ(Math.round((d / 256.0d) * ((double) this.ˋ)), (long) this.ˊ, this.ˋ - 1) + this.ॱ));
    }

    public long ˋ(long j) {
        long j2 = j - this.ॱ;
        if (!ˊ() || j2 <= ((long) this.ˊ)) {
            return 0;
        }
        long[] jArr = (long[]) amm.ॱ(this.ʼ);
        double d = (((double) j2) * 256.0d) / ((double) this.ˋ);
        int ˊ = anr.ˊ(jArr, (long) d, true, true);
        long ˊ2 = ˊ(ˊ);
        long j3 = jArr[ˊ];
        long ˊ3 = ˊ(ˊ + 1);
        long j4 = ˊ == 99 ? 256 : jArr[ˊ + 1];
        return Math.round((j3 == j4 ? 0.0d : (d - ((double) j3)) / ((double) (j4 - j3))) * ((double) (ˊ3 - ˊ2))) + ˊ2;
    }

    public long g_() {
        return this.ˎ;
    }

    public long ˎ() {
        return this.ˏ;
    }

    private long ˊ(int i) {
        return (this.ˎ * ((long) i)) / 100;
    }
}
